//状态对象的实现
//投票结果状态对象
var ResultState = function(){
	//判断结果保存在内部状态中
	var States = {
		//每种状态作为一种独立方法保存
		state0 : function(){
			//处理结果0
			console.log('这是第一种状况')
		},
		state1 : function(){
			//处理结果1
			console.log('这是第二种情况')
		},
		state2 : function(){
			//处理结果2
			console.log('这是第三种情况')
		},
		state3 : function(){
			//处理结果3
			console.log('这是第四种情况')
		}
	}
	//获取某一种状态并执行其对应的方法
	function show(result){
		States['state'  + result] && States['state' + result]();
	}
	return {
		//返回调用状态方法接口
		show : show
	}
}();
ResultState.show(3);

//超级玛丽
var lastAction = '';
function changeMarry(action){
	if(action == 'jump'){
		//
	}else if(action == "move"){
		//
	}else{
		//
	}
	lastAction = action;
}
//
var lastAction1 = '';
var lastAction2 = '';
function changeMarry(action1, action2){
	if(action1 == 'shoot'){
		//
	}else if(action1 == 'jump'){
		//
	}else if(action1 == 'move' && action2 == 'shoot'){
		//
	}else if(action1 == 'jump' && action2 == 'shoot'){
		//
	}
	//
	lastAction1 = action1 || '';
	lastAction2 = action2 || '';
}

//状态的优化
var MarryState = function(){
	var _currentState = {},
	states = {
		jump : function(){
			console.log('jump');
		},
		move : function(){
			console.log('move');
		},
		shoot : function(){
			console.log('shoot');
		},
		squat : function(){
			console.log('squat');
		}
	};
	var Action = {
		changeMarry : function(){
			var arg = arguments;
			_currentState = {};
			if(arg.length){
				for(var i = 0, len = arg.length; i < len; i++){
					_currentState[arg[i]] = true;
				}
			}
				// console.log(arg);
			return this;
		},
		goes : function(){
			console.log('触发一次动作');
			for(var i in _currentState){
				states[i] && states[i]();
			}
			return this;
		}
	}
	return {
		change : Action.changeMarry,
		goes : Action.goes
	}
}

// MarryState()
// 	.change('jump', 'shoot')
// 	.goes()
// 	.change('shoot')
// 	.goes();

	var marry = new MarryState();
	marry
	.change('jump', 'shoot')
	.goes()
	.change('shoot')
	.goes();
